from django.shortcuts import render

# Create your views here.
from rest_framework.generics import ListAPIView, RetrieveAPIView

from activities.models import Activities
from activities.serializers import ActivityListSerializer, ActivityDetailSerializer


class ActivitiesView(ListAPIView):
    # 查询数据并返回到前端
    serializer_class = ActivityListSerializer
    queryset = Activities.objects.all().order_by("-start_time")  # 由于倒叙排序，所以直接在查询集中指明


class ActivityDetailView(RetrieveAPIView):
    # 需要弄清genericVIEW,genericView中提供get_object()和quertset()方法，
    # 当需要查询某一id的详情信息，可以使用retrieve的视图，需要前段传id,此时需要指明queryset,后面会继续判断，是否有pk，有pk则会对查询集进一步过滤，使用的查询值为get_object的结果。
    # get_object方法来源get_queryset,而且
    serializer_class = ActivityDetailSerializer

    queryset = Activities.objects.all()
